package com.android.model;

import android.util.Log;
import android.view.View;

import com.android.bean.ResponseData;
import com.android.bean.User;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class LoginModelImpl implements LoginModel{
    private final static String TAG = "LoginModelImpl";
    @Override
    public void longin(String account,String password,final LoginListener loginListener) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://47.107.52.7:88/member/")
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .build();

        longinHttp_Interface request  = retrofit.create(longinHttp_Interface.class);

        Observable<ResponseData<User>> observable =
                request.getObservableTest(password, account);


        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResponseData<User>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull ResponseData<User> userResponseData) {
                        loginListener.onSuccess(userResponseData);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
